package com.good.jzhouse.controller;

import com.good.jzhouse.bean.Message;
import com.good.jzhouse.dao.MessageDao;
import com.good.jzhouse.tools.ApplicationUtil;
import com.good.jzhouse.tools.SendMsg;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Timestamp;
import java.util.Date;
import java.util.Map;

/**
 * @Author: xiaolei
 * @Date: 2021/3/14 19:18
 */
@RequestMapping("/public")
@Controller
public class PublicController {
    @RequestMapping("/login")
    public String goLogin(){
        return "login";
    }
    @RequestMapping("/register")
    public String goRegister(){
        return "register";
    }

    @ResponseBody
    @RequestMapping("/Message")
    public boolean SendMessage(String phone){
        System.out.println(phone);
       Map map = SendMsg.sendMessage(phone);
       System.out.println(map.get("Success"));
       if(map.get("Success").equals("true")){

            return true;
       };
        return false;
    }

    @ResponseBody
    @RequestMapping("/test")
    public boolean test(){
         Message message = new Message(null,"13650444529", "9527", new Timestamp(new Date().getTime()));
        int success = ApplicationUtil.context.getBean(MessageDao.class).insertMessage(message);
        if (success>0){
            return  true;
        }
        return false;
    }
}
